package com.ruoyi.ylxt.ksgl.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import java.io.InputStream;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.ylxt.ksgl.domain.KsGl;
import com.ruoyi.ylxt.ksgl.service.IKsGlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科室管理Controller
 *
 * @author huacai
 * @date 2025-01-13
 */
@RestController
@RequestMapping("/ylxt/gl")
public class KsGlController extends BaseController
{
    @Resource
    private IKsGlService ksGlService;

    /**
     * 查询科室管理列表
     */
    @PreAuthorize("@ss.hasPermi('ylxt:gl:list')")
    @GetMapping("/list")
    public TableDataInfo list(KsGl ksGl)
    {
        startPage();
        List<KsGl> list = ksGlService.selectKsGlList(ksGl);
        return getDataTable(list);
    }

    /**
     * 导出科室管理列表
     */
    @PreAuthorize("@ss.hasPermi('ylxt:gl:export')")
    @Log(title = "科室管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KsGl ksGl)
    {
        List<KsGl> list = ksGlService.selectKsGlList(ksGl);
        ExcelUtil<KsGl> util = new ExcelUtil<KsGl>(KsGl.class);
        util.exportExcel(response, list, "科室管理数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<KsGl> util = new ExcelUtil<KsGl>(KsGl.class);
        util.importTemplateExcel(response, "科室管理数据");
    }

    /**
     * 导入数据
     */
    @Log(title = "科室管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('ylxt:gl:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<KsGl> util = new ExcelUtil<KsGl>(KsGl.class);
        InputStream inputStream = file.getInputStream();
        List<KsGl> list = util.importExcel(inputStream );
        inputStream.close();
        int count = ksGlService.batchInsertKsGl(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }

    /**
     * 获取科室管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ylxt:gl:query')")
    @GetMapping(value = "/{ksglId}")
    public AjaxResult getInfo(@PathVariable("ksglId") String ksglId)
    {
        return success(ksGlService.selectKsGlByKsglId(ksglId));
    }

    /**
     * 新增科室管理
     */
    @PreAuthorize("@ss.hasPermi('ylxt:gl:add')")
    @Log(title = "科室管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KsGl ksGl)
    {
        return toAjax(ksGlService.insertKsGl(ksGl));
    }

    /**
     * 修改科室管理
     */
    @PreAuthorize("@ss.hasPermi('ylxt:gl:edit')")
    @Log(title = "科室管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KsGl ksGl)
    {
        return toAjax(ksGlService.updateKsGl(ksGl));
    }

    /**
     * 删除科室管理
     */
    @PreAuthorize("@ss.hasPermi('ylxt:gl:remove')")
    @Log(title = "科室管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ksglIds}")
    public AjaxResult remove(@PathVariable String[] ksglIds)
    {
        return toAjax(ksGlService.deleteKsGlByKsglIds(ksglIds));
    }
}
